<%--
  Created by IntelliJ IDEA.
  User: dream
  Date: 14-4-4
  Time: 下午11:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="../header.jsp"%>
<jsp:include page="../taglib.jsp"></jsp:include>
<html>
<head>
    <title></title>
</head>
<body>
<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'west',split:true,border:false" style="width:250px">
        <table id="perRole_table1" class="default_table">
        </table>
    </div>
    <div data-options="region:'center',border:false">
        <div style="margin:5px 10px; padding:50% 2px;">
            <br/>
            <br/>
            <br/>
            <br/>
            <br/>
            <br/>
            <a href="#" class="easyui-linkbutton" onclick="perUserRole_add();" >左移</a>
            <br/>
            <br/>
            <a href="#" class="easyui-linkbutton" onclick="perUserRole_remove();">右移</a>
        </div>
    </div>
    <div data-options="region:'east',split:true,border:false" style="width:250px">
        <table id="perRole_table2" class="default_table">
        </table>
    </div>
</div>
<script>
    var perRole_table1 = $('#perRole_table1');
    var perRole_table2 = $('#perRole_table2');
    $(function () {
        initPerRoleTable(perRole_table1,'已有角色','1');
        initPerRoleTable(perRole_table2,'可用角色','2');
    })
    function initPerRoleTable(perRole_table,title,type){
        var urlParams = '?type='+type+'&perUserId='+'${perUserId}';
        perRole_table.initGrid({
            title:title,
            url: '${ctx}/perUserRole/getGridData.do'+urlParams,
            pagination:false,
            fitColumns:true,
            pageSize:100,
            columns: [
                [
                    {field: 'ck', checkbox: true},
                    {field: "id", title: "ID", align: 'center', hidden: true},
                    {field: 'name', title: '名称', width:100,align: 'center'}
                ]
            ]
        });
    }

    function perUserRole_add(){
        var ids = perRole_table2.getSelectIds();
        if(ids==null){
            $.alertBox('系统提示', '请选择要赋予的角色', 'info');
            return false;
        }
        $.commonAjax( '${ctx}/perUserRole/savePerUserRole.do', {ids: ids,perUserId:'${perUserId}'},{success:function(data){
            initPerRoleTable(perRole_table1,'已有角色','1');
            initPerRoleTable(perRole_table2,'可用角色','2');
        }});
    }
    function perUserRole_remove(){
        var ids = perRole_table1.getSelectIds();
        if(ids==null){
            $.alertBox('系统提示', '请选择要赋予的角色', 'info');
            return false;
        }
    }
</script>
</body>
</html>